package com.air.ota.service.imp;

import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.air.common.service.imp.BaseServiceImp;
import com.air.common.util.QueryCondition;
import com.air.common.util.QueryExpression;
import com.air.ota.dao.CancelTransDao;
import com.air.ota.mo.CancelTrans;
import com.air.ota.service.ICancelTransService;

@Service("cancelTransService")
public class CancelTransServiceImp extends BaseServiceImp implements
		ICancelTransService, InitializingBean {
	
	@Autowired
	CancelTransDao cancelTransMapper;
	
	@Override
	public void afterPropertiesSet() throws Exception {
		this.baseDao = cancelTransMapper;
	}

	@Override
	public CancelTrans insertOrUpdate(CancelTrans trans) throws Exception {
		QueryCondition condition = new QueryCondition();
		condition.addQueryCondition("cancelSequence",trans.getCancelSequence(), QueryExpression.EQUALS);
		condition.addQueryCondition("cellphone",trans.getCellphone() , QueryExpression.EQUALS);
		List<CancelTrans> result= this.queryByCondition(condition);
		
		if (result!=null&&result.size()>0){//update
			Integer id = ((CancelTrans)result.get(0)).getId();
			trans.setId(id);
			this.updateById(trans);
		}else{//insert
			this.insert(trans);
		}
		
		return trans;
	}

}
